package com.heima.admin.service.impl;

import com.heima.admin.service.ManualAuditService;
import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.admin.dtos.NewsAuthDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Slf4j
public class ManualAuditServiceImpl implements ManualAuditService {
    @Autowired
    private IWemediaClient mediaClient;
    /**
     * 查询文章列表
     * @param dto
     * @return
     */
    @Override
    public ResponseResult listQuery(NewsAuthDto dto) {
        //获取pageReqDto对象
        WmNewsPageReqDto pageReqDto = new WmNewsPageReqDto();
        BeanUtils.copyProperties(dto,pageReqDto);
        pageReqDto.setStatus(dto.getStatus().shortValue());
        pageReqDto.setKeyword(dto.getTitle());
        //查询列表
        ResponseResult responseResult = mediaClient.wmNewsList(pageReqDto);
        return responseResult;
    }

    /**
     * 查询文章详情
     *
     * @param id 自媒体文章id
     * @return
     */
    @Override
    public ResponseResult detailsQuery(Integer id) {
        //校验参数
        if(id == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //查询数据
        ResponseResult responseResult = mediaClient.detailsQuery(id);

        return responseResult;
    }
    /**
     * 审核成功或失败
     *
     * @param dto
     * @return
     */
    @Override
    public ResponseResult changeStatus(NewsAuthDto dto) {
        //参数校验
        if(dto == null){
            return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
        }
        //具体实现
        ResponseResult responseResult = mediaClient.yesOrNo(dto);

        return responseResult;
    }
}
